<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<head th:replace="fragments/header :: head"></head>
<body>
<div th:replace="fragments/header :: navbar"></div>
<div class="container pt-5">
    <h3 class="text-center">新增用户</h3>
    <div class="row justify-content-center">
        <div class="col-md-4">
            <div class="alert alert-success" th:if="${successMessage}"
                 th:utext="${successMessage}">
            </div>
            <form name="userForm" role="form" method="post" th:object=
                    "${user}" th:action="@{/users/add}">
                <div class="form-group">
                    <input type="hidden" class="form-control" id="id"
                           name="id" th:field="*{userId}"/>
                </div>

                <div class="form-group">
                    <label class="form-control-label" for="login">登录名称</label>
                    <input type="text" class="form-control" id="login"
                           name="login" th:field="*{userName}" required
                           maxlength="50" pattern="^[_'.@A-Za-z0-9-]*$">
                    <div th:if="${#fields.hasErrors('userName')}">
                        <small class="form-text text-danger" th:errors="*{userName}">
                        </small>
                    </div>
                </div>
                <div class="form-group">
                    <label class="form-control-label" for="userFullname">用户全名</label>
                    <input type="text" class="form-control" id="userFullname"
                           th:field="*{userFullname}" name="userFullname" required
                           maxlength="50" pattern="^[\u4e00-\u9fa5]{0,}*S">
                    <div th:if="${#fields.hasErrors('userFullname')}">
                        <small class="form-text text-danger" th:errors="*{userFullname}">
                        </small>
                    </div>
                </div>
                <div class="form-group">
                    <label class="form-control-label" for="password">用户密码
                    </label>
                    <input type="password" class="form-control" id="password" required
                           name="password" th:field="*{userPassword}" maxlength=50>
                    <div th:if="${#fields.hasErrors('userPassword')}">
                        <small class="form-text text-danger" th:errors="*{userPassword}">
                        </small>
                    </div>
                </div>
                <div class="form-group">
                    <label class="form-control-label" for="userPhone">用户电话</label>
                    <input type="text" class="form-control" id="userPhone"
                           th:field="*{userPhone}" name="userPhone" required
                           maxlength="11" pattern="^[0-9]*$">
                    <div th:if="${#fields.hasErrors('userPhone')}">
                        <small class="form-text text-danger" th:errors="*{userPhone}"></small>
                    </div>
                </div>
                <div class="form-group">
                    <label class="form-control-label" for="userAddress">用户地址</label>
                        <input type="text" class="form-control" id="userAddress"
                               th:field="*{userAddress}" name="userAddress" required
                               maxlength="120" pattern= "^[\u4e00-lu9fa5_a-zA-Z0-9]*$">
                        <div th:if="${#fields.hasErrors('userAddress')}">
                            <small class="form-text text-danger" th:errors="*{userAddress}">
                            </small>
                        </div>
                </div>
                <div class="form-group">
                    <label class="form-control-label" for="userBankcard">银行卡号</label>
                        <input type="text" class="form-control" id="userBankcard" th:field="*{userBankcard}"
                               name="userBankcard" required maxlength="80" pattern="^[0-9]*$">
                        <div th:if="${#fields.hasErrors('userBankcard')}">
                            <small class="form-text text-danger" th:errors="*{userBankcard}">
                                </small>
                        </div>
                </div>
            <div class = "col-12 text-right">
                <a type="button" class="btn btn-secondary" th:href="@{/users}">返回</a>
                <button type="submit" class="btn btn-primary">新建</button>
            </div>
        </form>
        </div>
    </div>
</div>
</body>
</html>